package com.ruoyi.vplat.websocket.listener;

import java.util.HashMap;

import javax.websocket.Session;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.event.NetworkEvent;
import com.ruoyi.common.websocket.handler.AbstractWebsocketMsgHandler;
import com.ruoyi.common.websocket.listener.WsOpenListener;

@Component
public class EdgeWsOpenListener implements WsOpenListener{
	@Autowired
	private ApplicationEventPublisher eventPublisher;
	@Override
	public void onOpen(String username, Session session) {
		JSONObject res = AbstractWebsocketMsgHandler.getCommandTemplate("90002",new HashMap<String, Object>(){{
			put("protocol", 10000);
			put("seqNum", AbstractWebsocketMsgHandler.getRandomNum(9));
			put("terminateId", username);
		}});
		//统一交给ruoyi-network-server模块处理,方便代码维护
		eventPublisher.publishEvent(new NetworkEvent(this, res.toString()));
		
	}

}
